FormUtil = {
	retriveInfo: function(formId) {
		if (formId == null) {
			return Vari.frm;
		}
		
		var rt = null;				
		$.ajax({
			type : 'GET',
			dataType : 'json', contentType: "application/json",
			async : false,
			url : Vari.ApiRestV1 + 'form/' + formId,

			success : function(json) {
				rt = FormUtil.genFormVo(json.frm);								
			}
		});				
		return rt;
	},
			
	clearForm: function(fieldContext) {
		var containerView = Em.View.views['form_canvas_view'];
		containerView.removeAllChildren();		
		$('#form_canvas_view .ember-view').remove();
	},
	changeVal: function(e) {		
		var p = e.closest("fieldset");
		p.find("input:hidden").val(e.val());
	},
	genFormVo: function (formTo, i){
		var formVo = App.FormVo.create();
		
		Ember.mixin(formVo, {
			id: formTo.id,
			headline: formTo.headline,
			oncePerIp: formTo.oncePerIp,
			showButton: formTo.showButton,
			status: formTo.status,
			apiVer: formTo.apiVer,
			displayQrCode: formTo.displayQrCode,
			userId: formTo.userId,
			updateTime: $.dformat.date(formTo.updateTime, "dd/MM/yyyy"),
			num: i
		});
		var fieldVos = [];
		formTo.fields.forEach(function(fieldTo) {
			var fieldVo = FieldUtil.genFieldVo(fieldTo);			
			fieldVos.pushObject(fieldVo);
			Vari.fieldMap.set(fieldVo.get("uid"), fieldVo);
		});
		
		Ember.mixin(formVo, {
			fields: fieldVos,
		});
		//console.log(formVo);
		return formVo;
	},
};